local guixin = fk.CreateSkill{
  name = "ibeia__guixin",
}

Fk:loadTranslationTable{
  ["ibeia__guixin"] = "归心",
  [":ibeia__guixin"] = "当你造成或受到伤害后，你可以令受伤角色获得伤害来源牌，其可以令你摸一张牌。",

  ["#ibeia__guixin-give"] = "归心：可以令%dest获得%arg",
  ["#ibeia__guixin-draw"] = "归心：可以令%dest摸一张牌",
}

guixin:addEffect(fk.Damage, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("ibeia__guixin") and player == target and not data.to.dead and
      data.card and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = "ibeia__guixin",
      prompt = "#ibeia__guixin-give::" .. data.to.id .. ":" .. data.card:toLogString(),
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:obtainCard(data.to, data.card, true, fk.ReasonJustMove, player, guixin.name)

    if player.dead or data.to.dead then return end
    local ivk = room:askToSkillInvoke(data.to, {
      skill_name = "ibeia__guixin",
      prompt = "#ibeia__guixin-draw::" .. player.id,
    })

    if not ivk then return end
    player:drawCards(1, guixin.name)
  end,
})

guixin:addEffect(fk.Damaged, {
  anim_type = "masochism",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill("ibeia__guixin") and player == target and
      data.card and player.room:getCardArea(data.card) == Card.Processing
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = "ibeia__guixin",
      prompt = "#ibeia__guixin-give::" .. data.to.id .. ":" .. data.card:toLogString(),
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:obtainCard(data.to, data.card, true, fk.ReasonJustMove, player, guixin.name)

    if player.dead or data.to.dead then return end
    local ivk = room:askToSkillInvoke(data.to, {
      skill_name = "ibeia__guixin",
      prompt = "#ibeia__guixin-draw::" .. player.id,
    })

    if not ivk then return end
    player:drawCards(1, guixin.name)
  end,
})

return guixin
